﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NServiceBus;
using Framework.Event;
using Framework.Infrastructure;
using Framework.Config;

namespace Framework.Bus
{
    public class EventSubscriber : IHandleMessages<IDomainEvent>
    {
        #region IMessageHandler<IDomainEvent> Members
        IMessageDispatcher _MessageDispatcher;
        IMessageDispatcher MessageDispatcher
        {
            get
            {
                return _MessageDispatcher ??
                    (_MessageDispatcher = IoCFactory.Resolve<IMessageDispatcher>(Constants.Configuration.AsyncEventDispatcher));
            }
        }

        public void Handle(IDomainEvent message)
        {
            MessageDispatcher.DispatchMessage(message);
        }

        #endregion
    }
}
